<?php
require('../database/db.php');
$mysql=new mysql();
// 传入参数
$carid=$_REQUEST['carid'];
$number=$_REQUEST['number'];
// 传入参数 end
if ($carid!='' && $number>0) {
	$flag = true;
	// 查找商品数量并判断购买数量是否在商品数量的范围内
	$sql = "select goodsid from car where carid=".$carid;
	$goodsid = $mysql->getOne($sql);

	$sql = "select number from goods where goodsid=".$goodsid;
	$goodsNum = $mysql->getOne($sql);
	// 查找商品数量并判断购买数量是否在商品数量的范围内 end
	if ($goodsNum>=$number) {
		$sql = "UPDATE car set `number`='".$number."' where carid=".$carid;
		$query = $mysql->query($sql);
		if ($mysql->affected_rows()<=0) {
			$flag = false;
		}
		if ($flag) {
			$arr = array('code' => 100, 'tip' =>'修改成功');
		}else{
			$arr = array('code' => 300, 'tip' =>'修改失败');
		}
	}else{
		$arr = array('code' => 400, 'goodsNum' => $goodsNum,'tip' =>'购买数量大于商品库存数量,goodsNum为商品库存数量');
	}
}else{
	$arr = array('code' => 200, 'tip' =>'参数传入有误,需要传入参数:必传参数:购物车id=>carid;购买数量=>number(大于0)');
}
echo json_encode($arr);